package com.audaque.springboot.foshanupload.jwt.interceptor;

import com.audaque.springboot.foshanupload.jwt.component.JwtTokenProvider;
import com.audaque.springboot.foshanupload.jwtcore.component.iface.JwtProviderIface;
import com.audaque.springboot.foshanupload.jwtcore.properties.JwtProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author zgb
 * @desc 已登录则发放token然后转传到请求域
 * @date 2022-06-16 18:37:27
 */
//通过配置order()的值，值越小，优先级越高。不配默认是0
@Order(0)
public class JwtLoginInterceptor implements HandlerInterceptor {


    @Autowired
    private JwtProviderIface jwtProviderIface;

    @Autowired
    private JwtProperties jwtProperties;
    @Autowired
    private JwtTokenProvider jwtTokenProvider;



    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        jwtTokenProvider.sendToken(request,response);
        return true;
    }
}
